
/*

Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
using System;using BusinessLayer;using InfoClasses;using dpatoolkit.UILayer;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace dpatoolkit.UILayer
{
	/// <summary>
	/// Interface that has to be implemented by a Pen Cap Provider
	/// </summary>
	public class PenCapProvider
	{
		
		static CustomLineCap multiCap, aggrCap , inhCap , singleCap;
		
		static PenCapProvider()
		{
            GraphicsPath path = null, multiCapPath = null;
			int x = 0,y = 0;
            int width = 0, height = 0;
            int span = 0;
            Matrix translateMatrix = null;

			#region Multi and Single representation arrow code
            width = 8; height = 12;
            
			path = new GraphicsPath();
			path.StartFigure();
			path.AddPolygon(new PointF[]{ new PointF(0,0) , 
                new PointF(width/2,height),new PointF(width,0)});
            
            multiCapPath = path.Clone() as GraphicsPath;
            
            // set the single arrow.
            span = height;
            translateMatrix = new Matrix();
            translateMatrix.Translate(-width/2, -span);
            path.Transform(translateMatrix);
            singleCap = new CustomLineCap(null, path);
            singleCap.BaseInset = span;

            // set the multi arrow.
            multiCapPath.AddEllipse(new Rectangle(width / 4, height, width / 2, width / 2));
            span = height + width / 2;
			translateMatrix = new Matrix();
			translateMatrix.Translate(-width/2,-span);
            multiCapPath.Transform(translateMatrix);
            multiCap = new CustomLineCap(null, multiCapPath);
			multiCap.BaseInset=span;
            
			#endregion

			#region Diamond Cap code
            span = width = height = 12;
			// -- set the path
            path = new GraphicsPath();
			path.StartFigure();
			path.AddPolygon(new PointF[] { new PointF(0,height/2) , 
                new PointF(width/2,height),new PointF(width,height/2),
                new PointF(width/2,0)});
			path.CloseFigure();
            // --
			translateMatrix = new Matrix();
			translateMatrix.Translate(-height/2, -span);
			path.Transform( translateMatrix );
            // --
            aggrCap = new CustomLineCap(null, path);
			aggrCap.BaseInset=span;
			#endregion


			#region inheritance Cap
            x = 5; y = 10; span = 2 * y;
			// -- set the path
            path = new GraphicsPath();
			path.StartFigure();
			path.AddPolygon(new Point[]{ new Point(0,y) , new Point(x,0),new Point(y,y)});
            path.AddLine(x, y, x, span);
            path.CloseFigure();
            // --
			translateMatrix = new Matrix();
            translateMatrix.Translate(-x, -span);
			path.Transform( translateMatrix );
            // --
            inhCap = new CustomLineCap(null, path);
            inhCap.BaseInset = span;

			#endregion
		}

		public static CustomLineCap GetMultipleRepresentation()//returns a arrow + a circle
		{
			return multiCap;
		}

		public static CustomLineCap GetSingleRepresentation()//returns a arrow cap
		{
			//return arwCap;
			return singleCap;
		}
		
		public static CustomLineCap GetDiamondRepresentation()
		{
			return aggrCap;
			
		}

		public static CustomLineCap GetInheritanceRepresentation()
		{
			return inhCap;
			//return inhArwCap;
			
		}

	}
}
